/**
  ******************************************************************************
  * @file    TIM_Measure.c
  * @author  Hanif Rizal
  * @version V1.0.0
  * @date    18-Januari-2013
  * @brief   File ini memberikan fungsi firmware untuk menghitung waktu eksekusi
	*					 program dengan menggunakan timer
  *              
  *  @verbatim
  *  
  *          ===================================================================
  *                                 How to use this driver
  *          ===================================================================              
  *   
  *  @endverbatim
  *    
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2013 Vibration Monitoring System TEAM</center></h2>
  ******************************************************************************
  */
	
/* Includes ------------------------------------------------------------------*/
#include "TIM_Measure.h"

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

/**
  * @brief  Inisialisasi TIM untuk mode pengukuran.
  * @param  None
  * @retval None

  */
void Init_TIM_Measure(void)
{
	/* TIM2 clock enable */
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
	/* Time base configuration */
	TIM_TimeBaseStructure.TIM_Period = 4000; // 1 MHz down to 10 KHz (0.1 ms)
	TIM_TimeBaseStructure.TIM_Prescaler = 84; // Down to 1 MHz (adjust per your clock)
	TIM_TimeBaseStructure.TIM_ClockDivision = 0;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
}

/**
  * @brief  Fungsi untuk memulai penghitungan TIM
  * @param  None
  * @retval None

*/
void TIM_Start(void)
{
	/* TIM2 enable counter */
	TIM_Cmd(TIM2, ENABLE);
}

/**
  * @brief  Fungsi untuk mengetahui isi perhitungan dari TIM_Measure
  * @param  None
  * @retval Nilai hitungan eksekusi

 */
uint32_t TIM_Get_Count(void)
{
	return (TIM_GetCounter(TIM2));
}

/**
  * @brief  Fungsi untuk menghentikan penghitungan TIM
  * @param  None
  * @retval None

  */
void TIM_Stop(void)
{
	/* TIM2 enable counter */
	TIM_Cmd(TIM2, DISABLE);
}

/**
  * @brief  Fungsi untuk mereset hitungan TIM
  * @param  None
  * @retval None

 */
void TIM_Reset_Count(void)
{
	TIM_SetCounter(TIM2,0);
}
/******************* (C) COPYRIGHT 2013 Hanif Rizal *****END OF FILE****/
